package br.com.fidalgotecnologia.layar.handler;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import br.com.fidalgotecnologia.layar.constante.RequestHeaders;
import br.com.fidalgotecnologia.layar.constante.RequestParameters;
import br.com.fidalgotecnologia.layar.entity.LayerRequest;



public class RequestHandler {
	public static LayerRequest getLayerRequest(HttpServletRequest request){
		LayerRequest layerRequest = new LayerRequest();
		getHeaders(request, layerRequest);
		getParameters(request, layerRequest);
		return layerRequest;	
	}


	private static void getParameters(HttpServletRequest request, LayerRequest poiRequest) {
		if(request.getParameter(RequestParameters.USER_ID)!=null){			
			poiRequest.setUserId(request.getParameter(RequestParameters.USER_ID));
		}
		if(request.getParameter(RequestParameters.LAYER_NAME)!=null){
			poiRequest.setLayerName(request.getParameter(RequestParameters.LAYER_NAME));
		}
		if(request.getParameter(RequestParameters.VERSION)!=null){
			poiRequest.setVersion(request.getParameter(RequestParameters.VERSION));
		}
		if(request.getParameter(RequestParameters.LATITUDE)!=null){
			poiRequest.setLat(request.getParameter(RequestParameters.LATITUDE));
		}
		if(request.getParameter(RequestParameters.LONGETUDE)!=null){
			poiRequest.setLon(request.getParameter(RequestParameters.LONGETUDE));
		}
		if(request.getParameter(RequestParameters.COUNTRY_CODE)!=null){
			poiRequest.setCountryCode(request.getParameter(RequestParameters.COUNTRY_CODE));
		}
		if(request.getParameter(RequestParameters.LANGUAGE)!=null){
			poiRequest.setLang(request.getParameter(RequestParameters.LANGUAGE));
		}
		if(request.getParameter(RequestParameters.ACTION)!=null){
			poiRequest.setAction(request.getParameter(RequestParameters.ACTION));
		}
		if(request.getParameter(RequestParameters.ACCURACY)!=null){
			poiRequest.setAccuracy(request.getParameter(RequestParameters.ACCURACY));
		}
		if(request.getParameter(RequestParameters.PAGE_KEY)!=null){
			poiRequest.setPageKey(request.getParameter(RequestParameters.PAGE_KEY));
		}
		if(request.getParameter(RequestParameters.OAUTH_CONSUMER_KEY)!=null){
			poiRequest.setOauthConsumerKey(request.getParameter(RequestParameters.OAUTH_CONSUMER_KEY));
		}
		if(request.getParameter(RequestParameters.OAUTH_SIGNATURE)!=null){
			poiRequest.setOauthSignature(request.getParameter(RequestParameters.OAUTH_SIGNATURE));
		}
		if(request.getParameter(RequestParameters.OAUTH_SIGNATURE_METHOD)!=null){
			poiRequest.setOauthSignatureMethod(request.getParameter(RequestParameters.OAUTH_SIGNATURE_METHOD));
		}
		if(request.getParameter(RequestParameters.OAUTH_TIMESTAMP)!=null){
			poiRequest.setOauthTimestamp(request.getParameter(RequestParameters.OAUTH_TIMESTAMP));
		}
		if(request.getParameter(RequestParameters.OAUTH_NONCE)!=null){
			poiRequest.setOauthNonce(request.getParameter(RequestParameters.OAUTH_NONCE));
		}
		if(request.getParameter(RequestParameters.OAUTH_VERSION)!=null){
			poiRequest.setOauthVersion(request.getParameter(RequestParameters.OAUTH_VERSION));
		}
		if(request.getParameter(RequestParameters.RADIOLIST)!=null){
			poiRequest.setRadioList(request.getParameter(RequestParameters.RADIOLIST));
		}
		if(request.getParameter(RequestParameters.SEARCHBOX)!=null){
			poiRequest.setSearchBox(Arrays.asList(request.getParameterValues(RequestParameters.SEARCHBOX)));
		}
		if(request.getParameter(RequestParameters.CUSTOM_SLIDER)!=null){
			poiRequest.setSlider(Arrays.asList(request.getParameterValues(RequestParameters.CUSTOM_SLIDER)));
		}
		if(request.getParameter(RequestParameters.RADIUS)!=null){
			poiRequest.setRadius(request.getParameter(RequestParameters.RADIUS));
		}
		if(request.getParameter(RequestParameters.CHECKBOXLIST)!=null){
			poiRequest.setCheckBoxList(request.getParameter(RequestParameters.CHECKBOXLIST));
		}
		if(request.getParameter(RequestParameters.ALTITUDE)!=null){
			poiRequest.setAlt(request.getParameter(RequestParameters.ALTITUDE));
		}
		if(request.getParameter(RequestParameters.LOCAL_COUNTRY_CODE)!=null){
			poiRequest.setLocalCountryCode(request.getParameter(RequestParameters.LOCAL_COUNTRY_CODE));
		}
		if(request.getParameter(RequestParameters.REQUEST_POI_ID)!=null){
			poiRequest.setRequestedPoiId(request.getParameter(RequestParameters.REQUEST_POI_ID));
		}
	}


	private static void getHeaders(HttpServletRequest request, LayerRequest poiRequest) {
		poiRequest.setBrand(request.getHeader(RequestHeaders.BRAND));
		poiRequest.setModel(request.getHeader(RequestHeaders.MODEL));
		poiRequest.setOs(request.getHeader(RequestHeaders.OS));
		poiRequest.setOsVersion(request.getHeader(RequestHeaders.OS_VERSION));
		poiRequest.setLayarVersion(request.getHeader(RequestHeaders.LAYAR_VERSION));
		poiRequest.setPlayerVersion(RequestHeaders.PLAYER_VERSION);
	}

}
